The intended way is the Arceus distribution event — a limited-time Mystery Gift download that put the Azure Flute, and Arceus with it, into the game. If you missed the window, that route is closed.
The other method people suggest is a third-party cheat device such as an Action Replay, which can generate one directly. Worth being clear about the trade-off: unofficial codes can corrupt a save, and using them is against the spirit of the games. Legitimate past-event Pokémon are still traded around, so that is usually the better long-term answer.