Supposedly, Amazon does tons of backend real world optimization on shipping.
Say you, a SF resident, look at a book today on Amazon.com. Based on your past actions, Amazon knows very well how likely you are to purchase right away, or tomorrow, etc.
Now imagine the book isn't in a warehouse close enough to you for prime, but Amazon's data tells them you are much more likely to buy it when you come back to Amazon tomorrow if Prime is offered.
They'll ship the book to the warehouse in case you come back tomorrow to look at that book. Of course there's tons more modeling behind it to make sure they have very accurate estimates of the cost to pre emptively ship vs the payoff of you buying it, but that's the gist of it.
That was a few years ago, and it blew my mind at the time to think of all the optimization you can do in shipping to individuals when you're working at scale.
Amazon is more and more essentially running a CDN, but for the real world.