Since the last decade, transportation and distribution systems have experienced significant growth and development. Designing distribution systems utilizing electric vehicles is one of the main issues in this field. Accordingly, this research provides a novel solution method for a two-echelon distribution system using electric vehicles. At the first level, the required products are sent from a central depot to satellite stations. At the second level, these products are distributed among different customers. In routing electric vehicles, battery capacity and visiting charging stations are taken into consideration. In this regard, a mathematical model is developed for the electric vehicle routing at both levels. To solve the model, a newly developed meta-heuristic algorithm is proposed as Improved Moth-Flame Optimization (IMFO) Algorithm. The evaluation of IMFO indicates that, in small and medium-scale test problems, this algorithm has errors of about 1.2%. It also performs better than the classic moth-flame algorithm as well as the genetic algorithm on large-scale test problems. Moreover, the sensitivity analysis of the demand and time window parameters shows that a rise in demand leads to a sharp increase in the cost of the distribution system, but the opening of the time window can help to reduce costs.