Highly Experimental and suboptimal design:
It is precise enough not to need locked slots and only loads a little excess as it rounds the request up to the nearest full stack.
If you have a signal for the number of wagons you could even feed multiple train sizes with it as is. And if you have a signal encoding their location you could with minor modification work with that as well.