My question involves a traffic ticket from the state of: California

Last year I was driving back from the cannabis club and got pulled over with a couple friends in the car. The reason was because my tail lights were out. He then asked for my ID and proof of insurance. I did not have proof of insurance at the time but I was insured. He then searched my car without my consent(Although I didn't say he couldn't he just did it) and found my medical marijuana and my pipe. I had my Medical card at the time and showed it to him but he still wrote me a ticket and confiscated my meds(Less than a oz). Since then I had my tail lights fixed. So I was wondering if I play it right will I be able to get the charges dropped? Also I was wondering if I could get my meds returned as I am a legal Medical Marijauna Patient?
I am 19 years old and never have been to court.(Clean record)