Due to limited self-owned vehicles, online retailers often struggle to meet high demands for deliveries, especially during large promotions. This study employs machine learning to tackle this challenge by shipping products and renting vehicles in advance. We explore a large amount of historical demand data, enabling accurate forecasting of demand information. It is then combined with an improved meta-heuristic algorithm named the Improved Discrete Whale Optimization Algorithm (IDWOA) to help online retailers make optimal decisions. The algorithm involves a discretization method and an effective perturbation strategy, along with information sharing, Cauchy mutation, and an elimination strategy. Experimental results demonstrate that our method can reduce costs by 14.78% compared to temporary vehicle rentals, and it significantly outperforms other comparative algorithms. Therefore, our study effectively integrates machine learning algorithms with an improved meta-heuristic approach, allowing for increased utilization of data-driven advantages to enhance the precision and efficiency of vehicle rental and routing optimization.