This is the complicated version, but it's what I had to hand.
From bottom to top-
Convert the chest contents to O for future calculations.
Divide O by train capacity to get number of trains station can support.
Constant combinator provides train capacity, plus the number of trains a stacker can take.
Top three combinators output min(number of trains the station can take, and stacker capacity) as L for train limit.