Generally speaking, railroad-controlled equipment can either be in assigned service or designated a "free-runner." The primary difference is that assigned cars must be returned to the origin road/station when released empty. Free runners are not restricted and can be repositioned/reloaded to alternate destinations. Obviously, the latter can cut down on empty car-miles, but the assigned car practice is still extensively used to protect a customer's car supply. One pooling group is the North American Boxcar Pool: each road contributes a certain number of cars into the pool, and these cars free run. Empties are interchanged between roads as needed to correct imbalances. The class 1s also own TTX, whose car fleet also operates under a pooling methodology. All railroads have car distribution departments that have visibility into demand by location/car type and on-line car supply and position cars around the network as needed. Roads work closely together on this as well. (At least to the extent that competition allows!)
Regarding the economics of it all, car owners are compensated through two charges when their cars are off-line: Per diem (an hourly rate - used to be daily, hence "diem"), and mileage. The possessor road pays the car owner the entire time the car is on-line, loaded or empty, enroute or sitting on a customer's siding. These rates are negotiated bilaterally between each road, and varies by car type, owner, age, etc. These costs are figured into the rate to the extent that some rates are reporting mark dependent, i.e., the published rate will vary depending on who's boxcar is loaded.
A couple of chapters could be written on this, but I hope this summary helps.