Since the officer had finished the ticket and was leaving there could be doubt for a reasonable search of the car. Usually the police will say they had suspicion because of the actions of the driver or were looking for weapons so they were not in danger.
Whether or not this evidence is allowed is going to be up to the court.
To initiate a traffic stop, the officer must have at least a "reasonable suspicion" that the law was broken. If the officer actually saw the car speeding - the officer met the next higher legal standard of "probable cause" (in regard to the speeding violation).
While the officer was talking to the driver, perhaps smelling the inside of the vehicle, observing what was in the vehicle and perhaps saw signs of nervousness in the driver. The officer may have developed "probable cause" (based on his training and past experiences) to be 51% sure that contraband of some kind was in the car.
As soon as the officer handed over the ticket, and returned the driver's license etc, the driver was free to go. The temporary detention of the traffic stop was over.
The officer asked for permission to search the vehicle for contraband. It appears the driver did not give permission. The officer, then had to rely on his probable cause (or 51% sure) that the driver was carrying contraband based on on
...
talking to the driver, perhaps smelling the inside of the vehicle, observing what was in the vehicle and perhaps saw signs of nervousness in the driver
...
Obviously the police officers probable cause was correct when the contraband was located.
Below are links to the definition of:
- reasonable suspicion
- probable cause
- and the court decision affirming the authority of police to search vehicles under certain circumstances without a warrant or consent.
Hope this helps