Are headlights original or upgraded to LED or something else. For when the headlight was shaken and the bulb flickered it is possible a loose wire causes that. You would need to check the socket with a meter while moving it to see. The original bulb could have blown because of moisture in the housing, check for any. Also, the original bulb could have just been bad (even a bad contact in it) or it went because of the potential loose wire. The replacement could have blown due to oils from your fingers or contamination from something else deposited on the bulb and then when heated up the bulb overheated in that area.
A few possibilities, again first check plug for loose wire. Then check for condensation. Finally if all that checks out replace the bulb again but be sure to not touch it by finger or allow it to contact anything.
Good luck.