Railway freight transportation planning problem aims at determining trip plans of transporting various commodity demands within given time periods. Since freight transportation is typically performed for a group of train cars or blocks, decisions must be made on proper or optimized blocking. Integrating blocking decisions into trip planning generation process is a challenging problem. In this research, an optimization model is proposed to determine the route for a demand car to travel from its origin to destination, the blocks to be transported with and the sequence of trains to be assigned to, given the schedule of train services as well as train and yard capacities. The proposed model, similar to multicommodity network design model, has non-linear functions to represent hazardous material risks to be minimized. A preprocessing procedure is developed to reformulate the proposed model for more efficient computing and a heuristic solution method is designed for solving realistic freight transportation problem in practice. Numerical examples are presented to illustrate the developed mathematical model and the solution procedure.