When a multi-factor experiment is carried out over a period of time, the responses may depend on a time trend. Unless the tests of the experiment are conducted in a proper order, the time trend has a negative impact on the precision of the estimates of the main effects, the interaction effects and the quadratic effects. A proper run order, called a trend-robust run order, minimizes the confounding between the effects' contrast vectors and the time trend's linear, quadratic and cubic components. Finding a trend-robust run order is essentially a permutation problem. We develop a multistage approach based on integer programming to find a trend-robust run order for any given design. The multistage nature of our algorithm allows us to prioritize the trend robustness of the main-effect estimates. In the literature, most of the methods used are tailored to specific designs, and are not applicable to an arbitrary design.Additionally, little attention has been paid to trend-robust run orders of response surface designs, such as central composite designs, Box-Behnken designs and definitive screening designs. Our algorithm succeeds in identifying trend-robust run orders for arbitrary factorial designs and response surface designs with two up to six factors.