What a great idea. It would of course work fine; as long as all the goods on the train were going to the same place, and required at the same time. It is already being done, of course. If it was practical, and was going to actually work out cheaper, then it would be much more widespread.
But you, the great customer, demand that your supermarkets, petrol stations, restaurants, hotels, office suppliers, newsagents, car garages, bicycle shops, garden centres, corner shops, chemists, hospitals, vets, pubs, libraries, butchers, bakers and candlestick makers are all stocked with the items you want, at a time convenient to you.
That is the only reason lorries and their drivers are out there. Unlike a large proportion of cars, they are not clogging up the roads because it is vital that the kids get to the cinema to see the latest crap film; or that the occupants just have to get to the seaside for an ice cream before doing the same journey in reverse. No; lorries do not move a mile more than necessary. They burn a lot of expensive fuel, and their owners are a bit anal about making sure they are making money out of every drop of diesel.