My SA told me that the VIN is assigned when the car is manufactured; so presumably that's at some point as it's rolling down the line (it's etched/printed at various places all over the car, of course). If VINs are assigned in advance, I would imagine it's at most a day before- like planning for the next day's assemblies.
And the timeframe from manufacture to delivery is entirely dependent on where you live. I'm in the southeast, and I was told it takes at least two weeks to get cars from Fremont. I would imagine if you live in California it's like a day or two from manufacture to delivery.