This paper examines the feasibility of using waste heat from wastewater treatment plants (WWTPs) for water desalination. A model was developed to utilize waste heat from the gensets at As Samra WWTP in Jordan, using real data and TRNSYS® software to calculate available waste heat. The desalination process was then modeled with ASPEN PLUS® software, focusing on multi-effect desalination (MED). Both series and parallel configurations for the MED system were compared. The study investigated the effects of system feeding flow rate, feeding pressure, and heat input on productivity, performance ratio, and recovery ratio. The study also introduces a novel optimization technique combining machine learning and modern optimization algorithms to maximize system productivity and performance. Initially, a decision tree regression (DTR) model is developed to establish relationships between key independent variables (flow rate, feed pressure, and heat input) and dependent variables (productivity, performance ratio, and recovery ratio). The Pelican Optimization Algorithm (POA) is then used to identify the optimal values of the independent variables for maximum productivity and performance. The results show that using a series configuration yields a system productivity of 3984.2 kg/hr, a performance ratio of 3.78, and a recovery ratio of 0.991 at a feed flow rate of 4000 kg/hr, feed pressure of 3 bars, and heat input of 719 kW. Optimal productivity (4421 kg/hr), performance ratio (3.81), and recovery ratio (0.851) are achieved at a feed flow rate of 5166 kg/hr, feed pressure of 3.2 bars, and heat input of 794 kW. The techno-economic assessment indicates a levelized cost of water of 1.63 USD/m3 for parallel configurations and 1.65 USD/m3 for series configurations, with a payback period of less than two years.