Currently, the distribution of goods to factories is broken: If all consumers of a factories' good do not have anything in their storage, then the output goods is always sent to the same factory.
Patch attached. I do not know whether it break something else. Overflowing target factories still should be treated equally.
Does this problem only occur for just_in_time off?
Another solution would be to use the in transit number to distribute to the factories with least in store + in transit. This would also prefer closer factories more.
It effects only the just-in-time=off branch. There factories that are empty are not treated equally, the factory with the largest storage always wins.
The patch uses maximum storage and available storage at target factory in the same way as halt capacity and available halt capacity are used with just-in-time on.
Since we record now, how much is in transit: Maybe now the factory with the least percentage of goods in (storage+in transit)*100/max should get the delivery? (If possible)
I rather would first fix this, before thinking about alternatives.
Edit: Commited.