It is very important to jointly determine effective berth and quay crane allocation plan in order to make full use of the limited berth and quay crane resource and improve container terminal transportation efficiency. The uncertainty of ship's arrival time and the quantity of loading and unloading, however, will disrupt the execution of the berth and quay crane allocation plan and increase the cost. In order to minimize the total cost of time and position deviation, the optimal model of berth and quay crane allocation is proposed. The combination of SWO algorithm and PGA algorithm is presented to solve the optimization model, because SWO algorithm can effectively reduce the dimension of the solution and can avoid the PGA algorithm to converge to the local optimal solution. The correctness of the model and the validity of the algorithm are verified by numerical analysis.