You cannot use JailBreakMe method to jailbreak and unlock iOS 4.0.2 on iPhone 3G. However you can still jailbreak and unlock iPhone 3G using redsn0w. Here are the instructions:
Run RedSn0w and point it at the 4.0 IPSW. (Yes – point it at the 4.0 IPSW even though you’re at 4.0.2). This will also hacktivate your iPhone3G at 4.0.1 if you haven’t already been activated by iTunes.
If you need a carrier unlock – install ultrasn0w in Cydia (add repository http://repo666.ultrasn0w.com). For T-Mobile in the USA remember to turn off 3G mode in Settings→General→Network.
Have you already updated your device to the version iOS4 and want to unlock your 3GS? Firstly there was Redsn0w, now PwnageTool is available, which can easily help you. Here is a simple and easy tutorial for jailbreaking iPhone 3GS (old bootrom). Warning: this is not an official release and therefore may be some bugs that can destroy your device or delete some important information. So be careful while using it!