A method for designing an X-ray flatness filter for medical electron linac is developed. It is used in the optimization process in the electron beam radiation system. Monte Carlo simulation method is used and two examples of real radiation system optimization processes for China-made medical electron linac are provided: 15 MV X- ray system of BJ-20 linac, and 12 MeV electron system of BJ-14. Results are verified by using the traditional method.